package com.wisdudu.blank.support.widget.loading;

import android.animation.ObjectAnimator;
import android.app.ProgressDialog;
import android.content.Context;
import android.support.annotation.DrawableRes;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;

import com.wisdudu.blank.R;

/**
 * Created by qyf on 2016/10/11.
 */

public class LoadingProgressDialog extends ProgressDialog {

    private  ImageView mIvProgress;
    private TextView mMessageView;
    private ObjectAnimator mRotation;

    public LoadingProgressDialog(Context context) {
        super(context);
        initView(context);
    }

    public LoadingProgressDialog(Context context, int theme) {
        super(context, theme);
        initView(context);
    }

    private void initView(Context context) {
        this.setIndeterminate(true);
        this.show();
        setContentView(R.layout.dialog_progress_cus);
        mIvProgress = (ImageView) findViewById(R.id.iv_progress);
        mMessageView = (TextView) findViewById(R.id.message);
        mRotation = ObjectAnimator.ofFloat(mIvProgress, "rotation", 0f, 360f);
        mRotation.setRepeatCount(Animation.INFINITE);
        mRotation.start();
//        mLoadingDrawable = new LoadingDrawable(new MaterialLoadingRenderer(context));
//        mLoadingDrawable.start();
//        mIvProgress.setImageDrawable(mLoadingDrawable);
    }


    public void setProgressDrawable(@DrawableRes int progressDrawable) {
        this.mIvProgress.setImageResource(progressDrawable);
    }

    @Override
    public void setMessage(CharSequence message) {
        mMessageView.setText(message);
    }


    @Override
    public void dismiss() {
        super.dismiss();
    }

    public void endAnimation() {
        if(mRotation!=null){
            mRotation.end();
        }
    }
}
